<?php
$this->title = "Search";
$this->headTitle($this->title);
?>	
		
		<!-- start content -->
		<div id="search_inside" class="content">
				<div id="Search_panel">
					<h3><a href="#">Search Friends</a></h3>
					<div class="content">					
						<form id="frm_SearchFriends" name="frm_SearchFriends"  method="post">
							<label for="lbl_Friends">Search: </label>
							<input id="txt_SearchFriends" name="txt_SearchFriends"/><br/><br/>
							<label for="lbl_Conditions">Conditions: </label>
							<select name="ddl_Conditions1" id="ddl_Conditions1" style="width: 140px; font-family: Trebuchet MS; color: #64807c; font-size: 14px;">
								<option value="0" > </option>
								<?php foreach($this->condtions as $condtion){							
									echo "<option value=" . $condtion['id'] ." >".$condtion['Name']."</option>\n";								
								}?>						
							</select>
							<select name="ddl_Conditions2" id="ddl_Conditions2" style="width: 140px; font-family: Trebuchet MS; color: #64807c; font-size: 14px;">
								<option value="0" > </option>
								<?php foreach($this->condtions as $condtion){							
									echo "<option value=" . $condtion['id'] ." >".$condtion['Name']."</option>\n";								
								}?>						
							</select>
							<select name="ddl_Conditions3" id="ddl_Conditions3" style="width: 140px; font-family: Trebuchet MS; color: #64807c; font-size: 14px;">
								<option value="0" > </option>
								<?php foreach($this->condtions as $condtion){							
									echo "<option value=" . $condtion['id'] ." >".$condtion['Name']."</option>\n";								
								}?>						
							</select><br/><br/>
							<input type="submit" value="Search" id="btn_SearchFriends"  name="btn_SearchFriends"/>
							
						</form>
					</div>
					<h3><a href="#">Search Threads</a></h3>
					<div class="content" >
						<form id="frm_SearchThreads" name="frm_SearchThreads"  method="post" >
							<label for="lbl_Threads">Search: </label>
							<input id="txt_SearchThreads" name="txt_SearchThreads"/><br/><br/>
							<label for="lbl_Friends">Tags: </label>
							<input id="txt_SearchTag1" name="txt_SearchTag1" style="width: 110px"/>
							<input id="txt_SearchTag2" name="txt_SearchTag2" style="width: 110px"/>
							<input id="txt_SearchTag3" name="txt_SearchTag3" style="width: 110px"/><br/><br/>
							<input type="submit" value="Search" id="btn_SearchThreads"  name="btn_SearchThreads"/>
						</form>
					</div>
					<h3><a href="#">Search Groups</a></h3>
					<div class="content">
						<form id="frm_SearchGroups" name="frm_SearchGroups"  method="post">
							<label for="lbl_Groups">Search: </label>
							<input id="txt_SearchGroups" name="txt_SearchGroups"/><br/><br/>
							<input type="submit" value="Search" id="btn_SearchGroups"  name="btn_SearchGroups"/>
						</form>
					</div>					
				</div>
				
			<div id="SearchResults" >
				<?php if ($this->flag_search == 1){
						if (empty($this->found)){
							echo "There are not any threads that matched your criteria";
						}
						else{
							?>
						<table id="tbl_SearchResults">
						<tr>
							<th>Title</th>
							<th>Date Created</th>
						    <th>Author</th>
						    <th></th>
						</tr>
						<?php 	
						foreach($this->found as $thread){?>	
								<tr>						
								<td><?php echo $thread["Title"];?></td>			
								<td><?php echo $thread["DateCreated"];?></td>
								<td><?php echo $thread["username"];?></td>
								<td><a href="<?php echo $this->url(array('controller'=>'Threads','action'=>'viewthread'))."?id=". $thread["id"] ?>">View Thread</a></td>
								<tr>					
								<?php }	
						}?>
						</table>									
				<?php } else{
					if ($this->flag_search == 2){
						if (empty($this->found)){
							echo "There are not any users that matched your criteria";
						}
						else{
							?>
						<table id="tbl_SearchResults">
						<tr>
							<th>Name</th>
							<th>Surname</th>
							<th>UserName</th>						    
						    
						    <th>&nbsp;</th>
						    <th>&nbsp;</th>
						</tr>
						<?php 
						$session = Zend_Registry::get('session');							
						foreach($this->found as $user){?>	
								<tr>						
									<td><?php echo $user["FirstName"];?></td>			
									<td><?php echo $user["LastName"];?></td>
									<td><?php echo $user["Username"];?></td>
																
									<td><a href="<?php echo $this->url(array('controller'=>'Profile','action'=>'index'))."?id=". $user["id"] ?>">View profile</a></td>
									<td><a href="<?php echo $this->url(array('controller'=>'Friends','action'=>'sendrequest', 'sender'=>$session->user['id'], 'receiver'=>(int)$user["id"]))?>">Send request</a></td>
								<tr>					
								<?php }	
						}?>
						</table>	
					<?php }
					else{
						if ($this->flag_search == 3){
							if (empty($this->found)){
							echo "There are not any Groups that matched your criteria";
						}
						else{
							?>
						<table id="tbl_SearchResults">
						<tr>
							<th>Name</th>
							<th>Creator</th>						    
						    <th></th>
						</tr>
						<?php 	
						foreach($this->found as $group){?>	
								<tr>						
									<td><?php echo $group["Name"];?></td>			
									<td><?php echo $group["username"];?></td>								
									<td><a href="<?php echo $this->url(array('controller'=>'Group','action'=>'viewgroup'))."?id=". $group["id"] ?>">View Group</a></td>
								<tr>					
								<?php }	
						}?>
						</table>
						<?php }						
					}
				}?>
			
			</div>
		</div>
		
		
		<!-- end content -->
		
		